<?php 
namespace app\index\controller;

use \think\Controller;
use \think\Request;
use \think\Session;
use app\common\controller\Api as commonApi;
use app\user\traits\controllers\TraitUser;

/**
 * 前台预定流程(筛选分享与托管资源)
 */
class Filter extends commonApi 
{
    //前置操作 
    use TraitUser;
    protected $beforeActionList = [
    ];
    /**
     * [getfilter 筛选界面]房车
     * @return [type] [description]
     */
    public function getExList()
    { 
        //含有资源
        return $this->getExListForm();
        //城市列表
        $city = model('CarCalendar')->getCitys();
        $this->assign('city',$city);
        //心愿登陆
        $login = session('user.id') ? session('user.id') : 0;
        $this->assign('login',$login);
        //心愿登陆
        // 积分
        $integral = db('deposit')->where(['user_id'=>session("user.id"),'types'=>'integral'])->value("amount");
        $integral = $integral ? $integral : 0;
        $this->assign('integral',$integral);
        return view('filter/exlist',['list1'=>'','list2'=>'','s'=>'','e'=>'','a'=>'','b'=>'','k'=>'']);
    }
    /**
     * [postExListForm 筛选界面表单]
     * @return [type] [description]
     */
    public function getExListForm()
    {
        $filter_info['sdate'] = input('get.sdate');
        $filter_info['edate'] = input('get.edate');
        $filter_info['car_area']  = input('get.city'); 
        $k                    = input('get.city');
        //获取首页数据
        if (!empty(input('sdate'))) {
            $filter_info['sdate'] = input('sdate');
        }
        if (!empty(input('edate'))) {
            $filter_info['edate'] = input('edate');
        }
        if (!empty(input('city'))) {
           $filter_info['car_area']   = input('city');
        }
        $s     = $filter_info['sdate'];
        $e     = $filter_info['edate'];
        $list1 = model('CarCalendar')->queryCaravans($filter_info,1);

        // 推荐列表
        $filter_info['car_area'] = $this->ZoneArray([input('get.city')]);

        $list2 = model('CarCalendar')->queryCaravans($filter_info,1);

        $cates = db('car_cates')->column('name', 'id');
        //城市列表
        $city  = model('CarCalendar')->getCitys();
        $this->assign('city',$city);
        //积分
        $integral = db('deposit')->where(['user_id'=>session("user.id"),'types'=>'integral'])->value("amount");
        $integral = $integral ? $integral : 0;
        $this->assign('integral',$integral);
        //心愿登陆
        $login = session('user.id') ? session('user.id') : 0;
        $this->assign('login',$login);
        //心愿登陆
        return view('filter/exlist',['list1'=>$list1,'list2'=>$list2,'s'=>$s,'e'=>$e,'a'=>json_encode($cates),'b'=>json_encode(['1'=>'有','2'=>'无']),'k'=>$k]);
    }
    /**
     * [FunctionName 地点数组]
     * @param string $value [description]
     */
    public function ZoneArray(array $value = [])
    {
        $zone = ['Beijing','Shanghai','Sanya','Chengdu','Xian'];
        return array_diff($zone,$value);
    }
    /**
     * [postAjaxList2 加载列表2]
     * @return [type] [description]
     */
    public function postAjaxList2()
    {
        $filter_info = input('filter_info/a');
        $filter_info['car_area'] = $this->ZoneArray([$filter_info['car_area']]);
        $page        = input('page', 2);
        $list2       = model('CarCalendar')->queryCaravans($filter_info,$page);
        return $list2 ? json($list2) : false;
    }
    /**
     * [postAjaxList1 加载列表1]
     * @return [type] [description]
     */
    public function postAjaxList1()
    {
        $filter_info = input('filter_info/a');
        $page        = input('page', 2);
        $list1       = model('CarCalendar')->queryCaravans($filter_info,$page);
        return $list1 ? json($list1) : false;
    }
    /**
     * [getJumpError 错误界面]
     * @return [type] [description]
     */
    public function getJumpError()
    {
        return view('filter/cashlowtanchu');
    }
    public function getCheckUserLogin()
    {
        if (!session('user.id')) {
            return json(0);
        }
        return 1;
    }
}